package com.lottery.ruok.lottrey.activity;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

import com.lottery.ruok.lottrey.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class GetAwardActivityDialog extends FragmentActivity {

    @BindView(R.id.get_reward)
    View getReward;
    @BindView(R.id.window_close)
    ImageButton windowClose;
    private Unbinder bind;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.get_award_activity_dialog_layout);
        bind = ButterKnife.bind(this);
        setFinishOnTouchOutside(false);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (bind != null) {
            bind.unbind();
        }
    }

    @OnClick({R.id.get_reward, R.id.window_close})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.get_reward:
                if (!getTopActivity(this).equals(ActivitiesCenterActivity.class.getName())) {
                    startActivity(new Intent(this, ActivitiesCenterActivity.class));
                    finish();
                } else {
                    finish();
                }
                break;
            case R.id.window_close:
                finish();
                break;
        }
    }
    //判断当前界面显示的是哪个Activity
    public static String getTopActivity(Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
        ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
        return cn.getClassName();
    }
}
